package com.teach.hotel;


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * <pre>
 * 房间
 * ClassName : com.teach.Room
 * Author : J.L.Zhou
 * Date : 2019年6月2日 下午4:43:40
 * Version : V1.0
 * Copyright 2019 jlzhou.top Inc. All rights reserved. 
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目</pre>
 */
public class Room {
	
	public static Map<String, Room> rooms = new HashMap<>();

	private String num;
	private Boolean enable = false;
	private Type type;
	
	
	public String getNum() {
		return num;
	}
	public void setNum(String num) {
		this.num = num;
	}
	public Boolean getEnable() {
		return enable;
	}
	public void setEnable(Boolean enable) {
		this.enable = enable;
	}
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
	
	public static void menu(){
		System.out.println("-----------房间管理菜单----------");
		System.out.println(" 0. 返回管理菜单");
		System.out.println(" 1. 添加");
		System.out.println(" 2. 修改");
		System.out.println(" 3. 删除");
		System.out.println(" 4. 查看");
		System.out.println("-------------------------");
		Scanner in = new Scanner(System.in);
		int menu = in.nextInt();
		switch (menu) {
		case 1:
			add();
			break;
		case 2:
			update();
			break;
		case 3:
			delete();
			break;
		case 4:
			lookAll();
			break;

		default:
			SystemConsole.adminMenu();
			break;
		}
		menu();
	}
	
	
	public static void add(){
		Scanner in = new Scanner(System.in);
		System.out.println("请输入房间号：");
		String num = in.next();
		if(rooms.containsKey(num)){
			System.out.println("该房间号已经存在");
		}else{
			Type t = Type.selectType("请选择房型：");
			add(t,num);
		}
		System.out.println("添加房间成功");
	}
	
	public static void add(Type t,String num){
		Room r = new Room();
		r.setNum(num);
		r.setType(t);
		t.getList().add(r);
		rooms.put(num, r);
	}
	
	public static void update(){
		Scanner in = new Scanner(System.in);
		System.out.println("请输入房间号：");
		String num = in.next();
		Room r = rooms.get(num);
		if(r==null){
			System.out.println("不存在该房间");
		}else{
			Type t = Type.selectType("请修改后的房型：");
			r.type.getList().remove(r);
			r.setType(t);
			t.getList().add(r);
		}
	}
	
	public static void delete(){
		Scanner in = new Scanner(System.in);
		System.out.println("请输入房间号：");
		String num = in.next();
		Room r = rooms.get(num);
		if(r==null){
			System.out.println("不存在该房间");
		}else{
			r.type.getList().remove(r);
			rooms.remove(num);
		}
	}
	
	public static void lookAll(){
		System.out.println("------------房间列表-------------");
		System.out.println("房间号\t房型\t入住情况");
		for(Room r : rooms.values()){
			System.out.println(r.getNum()+"\t"+r.getType().getName()+"\t"+(r.getEnable()?"已入住":"空房间"));
		}
	}
	
	/**
	 * 选择空房
	 * @return
	 */
	public static Room selectEmpty(){
		Type t = Type.selectType("请选择的房型：");
		System.out.println("现有空房：");
		int count=0;
		for(int i=0;i<t.getList().size();i++){
			if(!t.getList().get(i).getEnable()){
				count++;
				System.out.print(t.getList().get(i).getNum()+"\t");
				if(count%7==0){
					System.out.println();
				}
			}
		}
		System.out.println("请输入房间号：");
		return rooms.get(new Scanner(System.in).next());
	}
	
	
}
